from .models import Log
from libs.enums import LogType


class LogService:
    def build_log(self, operator, obj, type, module, content):
        log = Log.objects.create(
            user=operator,
            content_object=obj,
            type=type,
            module=module,
            content=content
        )
        return log

    def build_create_log(self, operator, obj, module, content):
        self.build_log(operator, obj, LogType.CREATE.value, module, content)

    def build_delete_log(self, operator, obj, module, content):
        self.build_log(operator, obj, LogType.DELETE.value, module, content)

    def build_update_log(self, operator, obj, module, content):
        self.build_log(operator, obj, LogType.UPDATE.value, module, content)


log_service = LogService()
